package metadata

import (
	depmeta "github.com/romberli/das/internal/dependency/metadata"
)

const (
	TableGetByHostInfoAndDBNamePath                       = "/api/v1/metadata/table/host-info-db"
	TableGetStatisticsByHostInfoAndDBNameAndTableNamePath = "/api/v1/metadata/table/statistic/host-info-db"
	TableAnalyzeTableByHostInfoAndDBNameAndTableNamePath  = "/api/v1/metadata/table/analyze/host-info-db"

	TableHostInfoAndDBNameHTTPBodyTemplate             = `{"host_ip": "%s", "port_num": %d, "db_name": "%s", "login_name": "%s"}`
	TableHostInfoAndDBNameAndTableNameHTTPBodyTemplate = `{"host_ip": "%s", "port_num": %d, "db_name": "%s", "table_name": "%s", "login_name": "%s"}`
)

// TablesByDBID is the struct bind to JSON param
type TablesByDBID struct {
	Token     string `json:"token" binding:"required"`
	DBID      int    `json:"db_id" binding:"required"`
	LoginName string `json:"login_name" binding:"required"`
}

// NewTablesByDBID returns a new *TablesByDBID
func NewTablesByDBID(token string, dbID int, loginName string) *TablesByDBID {
	return &TablesByDBID{
		Token:     token,
		DBID:      dbID,
		LoginName: loginName,
	}
}

// GetToken returns the token
func (t *TablesByDBID) GetToken() string {
	return t.Token
}

// GetDBID returns the db id
func (t *TablesByDBID) GetDBID() int {
	return t.DBID
}

// GetLoginName returns the login name
func (t *TablesByDBID) GetLoginName() string {
	return t.LoginName
}

// TableByDBIDAndTableName is the struct bind to JSON param
type TableByDBIDAndTableName struct {
	Token     string `json:"token" binding:"required"`
	DBID      int    `json:"db_id" binding:"required"`
	TableName string `json:"table_name" binding:"required"`
	LoginName string `json:"login_name" binding:"required"`
}

// NewTablesByDBIDAndTableName returns a new *TableByDBIDAndTableName
func NewTablesByDBIDAndTableName(token string, dbID int, tableName, loginName string) *TableByDBIDAndTableName {
	return &TableByDBIDAndTableName{
		Token:     token,
		DBID:      dbID,
		TableName: tableName,
		LoginName: loginName,
	}
}

// GetToken returns the token
func (t *TableByDBIDAndTableName) GetToken() string {
	return t.Token
}

// GetDBID returns the db id
func (t *TableByDBIDAndTableName) GetDBID() int {
	return t.DBID
}

// GetTableName returns the table name
func (t *TableByDBIDAndTableName) GetTableName() string {
	return t.TableName
}

// GetLoginName returns the login name
func (t *TableByDBIDAndTableName) GetLoginName() string {
	return t.LoginName
}

type TableByHostInfoAndDBName struct {
	Token     string `json:"token" binding:"required"`
	HostIP    string `json:"host_ip" binding:"required"`
	PortNum   int    `json:"port_num" binding:"required"`
	DBName    string `json:"db_name" binding:"required"`
	LoginName string `json:"login_name" binding:"required"`
}

// NewTableByHostInfoAndDBName returns a new *TableByHostInfoAndDBName
func NewTableByHostInfoAndDBName(token string, hostIP string, portNum int, dbName, loginName string) *TableByHostInfoAndDBName {
	return &TableByHostInfoAndDBName{
		Token:     token,
		HostIP:    hostIP,
		PortNum:   portNum,
		DBName:    dbName,
		LoginName: loginName,
	}
}

// GetToken returns the token
func (t *TableByHostInfoAndDBName) GetToken() string {
	return t.Token
}

// GetHostIP returns the host ip
func (t *TableByHostInfoAndDBName) GetHostIP() string {
	return t.HostIP
}

// GetPortNum returns the port num
func (t *TableByHostInfoAndDBName) GetPortNum() int {
	return t.PortNum
}

// GetDBName returns the db name
func (t *TableByHostInfoAndDBName) GetDBName() string {
	return t.DBName
}

// GetLoginName returns the login name
func (t *TableByHostInfoAndDBName) GetLoginName() string {
	return t.LoginName
}

// TableByHostInfoAndDBNameAndTableName is the struct bind to JSON param
type TableByHostInfoAndDBNameAndTableName struct {
	Token     string `json:"token" binding:"required"`
	HostIP    string `json:"host_ip" binding:"required"`
	PortNum   int    `json:"port_num" binding:"required"`
	DBName    string `json:"db_name" binding:"required"`
	TableName string `json:"table_name" binding:"required"`
	LoginName string `json:"login_name" binding:"required"`
}

// NewTableByHostInfoAndDBNameAndTableName returns a new *TableByHostInfoAndDBNameAndTableName
func NewTableByHostInfoAndDBNameAndTableName(token string, hostIP string, portNum int, dbName string, tableName string, loginName string) *TableByHostInfoAndDBNameAndTableName {
	return &TableByHostInfoAndDBNameAndTableName{
		Token:     token,
		HostIP:    hostIP,
		PortNum:   portNum,
		DBName:    dbName,
		TableName: tableName,
		LoginName: loginName,
	}
}

// GetToken returns the token
func (t *TableByHostInfoAndDBNameAndTableName) GetToken() string {
	return t.Token
}

// GetHostIP returns the host ip
func (t *TableByHostInfoAndDBNameAndTableName) GetHostIP() string {
	return t.HostIP
}

// GetPortNum returns the port num
func (t *TableByHostInfoAndDBNameAndTableName) GetPortNum() int {
	return t.PortNum
}

// GetDBName returns the db name
func (t *TableByHostInfoAndDBNameAndTableName) GetDBName() string {
	return t.DBName
}

// GetTableName returns the table name
func (t *TableByHostInfoAndDBNameAndTableName) GetTableName() string {
	return t.TableName
}

// GetLoginName returns the login name
func (t *TableByHostInfoAndDBNameAndTableName) GetLoginName() string {
	return t.LoginName
}

type Tables struct {
	Tables []depmeta.Table `json:"tables"`
}

// NewTables returns a new *Tables
func NewTables(tables []depmeta.Table) *Tables {
	return &Tables{
		Tables: tables,
	}
}

// NewEmptyTables returns a new *Tables with empty values
func NewEmptyTables() *Tables {
	return &Tables{
		Tables: []depmeta.Table{},
	}
}

// GetTables returns the tables
func (t *Tables) GetTables() []depmeta.Table {
	return t.Tables
}
